function [ ] = plotAllStepFuncMACs(ctrS, filename, optfig)
IncludeCurve = true;
ctrS.level = 3e5;


min_level = min(ctrS.estim.bids.logE)-2;
max_level = max(ctrS.estim.bids.logE)+3;
ctrS.estim.bids.index = (1:height(ctrS.estim.bids))';
bids_mod = groupfilter(ctrS.estim.bids, "id_pp", @(x) x == min(x), "index");
%bids_mod = bids_mod(:, startsWith(bids_mod.Properties.VariableNames, ["id_pp" "id_period"]));
graphTable = table();
for i = 1:height(bids_mod)
    % Duplicate the current row
    duplicatedRow = repmat(bids_mod(i, :), 100, 1);
    
    % Create the "test" variable with values from 1 to 100
    duplicatedRow.logE = linspace(min_level, max_level, 100)';
    
    % Append the duplicated row to the new table
    graphTable = [graphTable; duplicatedRow];
end

graphTable.predictLogMAC=predict(ctrS.estim.fits{3}, graphTable);

for i = 1:max(ctrS.output_it.id_period)
    ctrS.period = i;
    filename_mod = strcat(filename, string(i));
    titlestring = strcat("MAC Step Functions Period ", string(i));
    plotStepFuncMACs(ctrS, graphTable(graphTable.id_period==i,:), IncludeCurve, ...
        filename_mod, titlestring, optfig)
end
end